﻿@using KPIS.GERP.Models.ICM
@model KPIS.GERP.Models.ICM.Committee
@{
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
    ViewBag.Title = "คณะกรรมการ";
    ViewBag.Descr = "เพิ่มข้อมูล" + ViewBag.Title + " ที่ร้องขอ";
   
}

@using (Html.BeginForm("CreateCommittee", "Dispose", FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()

    <div class="block-button-menu-above">
        <a class="btn button-standard-width btn-small btn-gray" data-rel="tooltip" href="#" 
        onclick="window.location.href='@Url.Action("IndexDisposeCommittee", new { DisposeId = Model.CommitteeGroupId })'" role="button"><i class="icon-reply bigger-120"></i>&nbsp;&nbsp;กลับไปหน้าแสดงข้อมูลทั้งหมด</a>
        @Html.ButtonSubmit()
    </div>
    
    @Html.ValidationSummary(true, KPIS.GERP.Models.Class.ValidateText.RequiredField, new { @class = "alert alert-error" })
    @Html.Partial("_CommitteeEditorForm")
}

@section scripts
{
    <script>
       
        $(function () {
            $('#ddlComFunctionId').val(75);
        });

        $(function () {
            ChangeEnableComType();

            $('#ddlEmpId').change(function () {
                var id = $('#ddlEmpId').val();
                var text = $('#ddlEmpId').find(":selected").text();
                $('#txtEmpName').val(text);

                if (id != '') {
                    $.getJSON('@Url.Action("GetEmployeeDetails", "Dispose")' + "/" + id, function (data) {
                        $("#txtEmpPositionName").val(data.Position == null ? "" : data.Position.Name);
                    });
                }
            });

            $('#ddlEmpId').change();
        });

        $('input[name=ComTypeId]').change(ChangeEnableComType);

        function ChangeEnableComType() {
            if ($('#rbtComType0').is(':checked')) {  
                $('#txtEmpName').attr('readonly', '');//.val($('#ddlEmpId option:selected').text());
                $('#ddlEmpId').removeAttr('disabled').trigger("liszt:updated");
                $('#txtEmpPositionName').attr('disabled', 'disabled');
                // reload  positioname
                $('#ddlEmpId').change();
            } else { 
                $('#ddlEmpId').attr('disabled', '').val("").trigger("liszt:updated");
                $('#txtEmpName').removeAttr('readonly').val("");
                $('#txtEmpPositionName').removeAttr('disabled', 'disabled').val("");
            }
            
        }

        $("form").submit(function (e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm(function (result) {
                if (result) {
                    currentForm.submit();
                }
            });
        });
    </script>
}